<?php

namespace App\Http\Requests\System\Config;

use App\Enum\Models\System\Config\Type;
use App\Models\System\Config;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * 通过查询数据库来验证数据的规则
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'title' => 'required|max:255',
            'name' => 'required|max:255|unique:App\Models\System\Config',
            'group' => [
                'required',
                Rule::in(Config::getDictGroup()->pluck('value')),
            ],
            // 'value' => '',
            'type' => [
                'required',
                Rule::enum(Type::class),
            ],
            'remark' => 'max:255',
            // 'prop' => '',
            'sort' => 'required|integer|gte:0',
            // 'rules' => '',
        ];
    }
}
